let includes = ([
    "include/common.js",
]);

let inherits = ([
    "inherit/data.js",
]);

function create() {
    return thisObject();
}

function validObject(ob) {

}

/**
 * 对象创建成功之后...
 * @param ob
 */
function validObjectAfter(ob) {

    os.debug("validObjectAfter be call" + ob.__fileName__);

    if (ob.__baseFileName__ == "adm/daemons/master/master.js") return true;

    if (ob.__baseFileName__ == "main/main.js") return true;

    //没有get方法的也不要处理了，先放过吧，以后优化
    if( undefinedp(ob.get) ) return  true;


    //如果是房间或者地图
    if (stringp(ob.get("obType")) && ob.get("obType") == "isRoom") {
        let key, file, nFile, nob, exits, exitKeys = Object.keys(ob.get("exits"))
        for (let exit in exitKeys) {
            key = exitKeys[exit];
            if (key == "") continue;
            file = ob.get("exits")[key];
            if (file == "") {
                os.debug(ob.__fileName__ + " the " + key + " side of this is not set, so continue ");
                continue;
            }
            nob = D(file);
            nFile = fileName(nob);
            os.debug("new room object filename is" + nFile);
            ob.get("exits")[key] = nFile;

            if (undefinedp(exits = nob.get("exits"))) {
                continue;
            }

            if (key == "west" && !undefinedp(exits["east"])) {
                if (exits["east"] == ob.__baseFileName__) {
                    nob.get("exits")["east"] = ob.__fileName__;
                }
            }
        }
    }
}


/**
 * 该方法负责构造一个连接对象
 * 流程和传统的OS一样。。。
 * @author Mike/Fang.j/大当家
 * @param ob
 */
function connect(agent) {
    //logind只能是唯一的
    let logoOb = D("adm/daemons/logind.js");
    return logoOb

}

/**
 * 实际上这个函数是OS内部的函数
 * 现在放到lib来实现吧，写JS就是舒服
 * @author Mike/Fang.j/大当家
 * @param ob
 */
function onMessage(agent, msg) {

    //查找这个agent是否 驱动要绑定这个agent才行..
    //这个LogoOb就是User类
    let userOb = os.getLogon(agent);

    if ( !objectp( userOb ) ) {
        thisObject().requireLogon(agent);
        return;
    }

    // //有连接器，检查连接器是否绑定了玩家
    // if (!objectp( logoOb.getTemp("bodyOb") )) {
    //     os.tellObject(logoOb, "请先登录...");
    //     return;
    // }

    //通过bodyOb发送消息
   // let bodyOb = logoOb.getTemp("linkOb");


    //先不管其他逻辑，直接发...
    userOb.commandHook(msg);

}

/**
 * 本质上这个方法应该是oS实现，
 * 所以会走connect方法让开发者做一次验证之类的事情
 * js嘛。。咱们粗暴点
 * @param agent
 */
function requireLogon(agent) {

    let logon = thisObject().connect(agent);
    os.debug("验证消息");
    //做登录验证
    logon.logon(agent);
}
